package algorithms;

import java.util.Arrays;

public class OddAndEvenArray {

	static boolean isEven(int n) {
		return n % 2 == 0;
	}
	
	static boolean isOdd(int n) {
		return !isEven(n);
	}
	
	public static void main(String[] args) {
		int[] mas = {2, 4, 6, 1, 3, 5};
		
		int size = mas.length;
		int oddIndex = 0;
		int evenIndex = 1;
		
		while (!(oddIndex == size - 2) && !(evenIndex == size - 1)) {
			
			if (!isOdd(mas[oddIndex])) {
				for (int i = oddIndex + 1 ; i < size; i+=2 ) {
					int curr = mas[i];
					if (isOdd(curr)) {
						mas[i] = mas[oddIndex];
						mas[oddIndex] = curr;
					}
				}
			}
			
			if (!isEven(mas[evenIndex])) {
				for (int i = evenIndex + 1 ; i < size - 1; i+=2 ) {
					int curr = mas[i];
					if (isEven(curr)) {
						mas[i] = mas[evenIndex];
						mas[evenIndex] = curr;
					}
				}
			}
			
			oddIndex += 2;
			evenIndex += 2;
		}
		
		System.out.println(Arrays.toString(mas));
	}
}